
import gameNetWorkState from "./SdkTools/gameNetWorkState";
import gameShareAdsVideo from "./SdkTools/gameShareAdsVideo";
import storage from "./SdkTools/storage";
import TopUi from "./TopUi";
import SDKManager from "./plat/SDKManager";

/**s
 * 增加体力s
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class addEngry extends cc.Component {
    @property(cc.Label)
    note:cc.Label = null

    @property(cc.Node)
    kuang:cc.Node = null

    @property(cc.Node)
    closenode:cc.Node = null

    private topuisc:TopUi = null
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.showUi()

        //Storage.Instance.nowEnery>=Define.maxEnery?this.note.string = '体力值已满，无需增加':this.note.string = '立即增加5点体力值' 
    }

    protected onEnable(): void {
        gameShareAdsVideo.Instance.bannerAds_Show()
        SDKManager.getInstance().showInterstitial();

        if(gameNetWorkState.Instance.getOpenState_Video()){
            cc.find('ling', this.kuang).active = !1
            cc.find('shuang', this.kuang).active = !0
        }else{
            cc.find('ling', this.kuang).active = !0
            cc.find('shuang', this.kuang).active = !1
        }
    }

    protected onDisable(): void {
        gameShareAdsVideo.Instance.bannerAds_Hide()
    }

    showUi(){
        var self = this
        this.kuang.scale = 0.3
        cc.tween(this.kuang)
        .to(0.1,{scale:1})
        .start()

        this.closenode.active = !1
        cc.tween(this.closenode)
        .delay(2)
        .call(()=>{
            self.closenode.active = !0
        })
        .start()
    }

    setTopUiSc(){
        console.log('++++++++++')

        let sc = cc.find('Canvas/top').getComponent(TopUi)
        if(sc){
            this.topuisc = sc
        }
        // let over = cc.find('Canvas/GameOver/top')
        // if(over){
        //     let sc2 = over.getComponent(TopUi)
        //     if(sc2){
        //         this.topuisc = sc2
        //     }
        // }
    }

    addBtnClick(){ 
        let self = this
        SDKManager.getInstance().showRewardVideos(null,null,()=>{
            storage.Instance.setEnergy(storage.Instance.nowEnery+1)
            if(self.topuisc){
                self.topuisc.setTiLi()
            }
            self.closeBtnClick()
        }, ()=>{})
        
    }

    addBtnClick2(){
        let self = this
        SDKManager.getInstance().showRewardVideos(null,null,()=>{
            storage.Instance.setEnergy(storage.Instance.nowEnery+10)
            if(self.topuisc){
                self.topuisc.setTiLi()
            }
            self.closeBtnClick()
        }, ()=>{})
        
    }

    closeBtnClick(){
        this.node.removeFromParent(true)
    }

    start () {

    }

    // update (dt) {}
}
